using System;
using UnityEngine;

[Serializable]
public class Mission
{
	public int missionOrder;

	public MissionType type;

	public float amount;

	private string PrefKeyProgress => "DailyMissionProgress" + missionOrder;

	private string PrefKeyCollect => "DailyMissionCollect" + missionOrder;

	public float CurrentProgress
	{
		get
		{
			return PlayerPrefs.GetFloat(PrefKeyProgress, 0f);
		}
		set
		{
			PlayerPrefs.SetFloat(PrefKeyProgress, value);
		}
	}

	public bool Collected
	{
		get
		{
			return PlayerPrefs.GetInt(PrefKeyCollect, 0) == 1;
		}
		set
		{
			if (value && IsDone)
			{
				PlayerPrefs.SetInt(PrefKeyCollect, 1);
			}
			else if (!value)
			{
				PlayerPrefs.SetInt(PrefKeyCollect, 0);
			}
		}
	}

	public string Description
	{
		get
		{
			string result = string.Empty;
			switch (type)
			{
			case MissionType.Kill:
				result = $"Kill {amount} enemies";
				break;
			case MissionType.Shoot:
				result = $"Shoot {amount} bullets";
				break;
			case MissionType.ClearWave:
				result = $"Clear {amount} waves";
				break;
			case MissionType.DealDamage:
				result = $"Deal {amount} damage";
				break;
			case MissionType.Run:
				result = $"Move {amount} units";
				break;
			case MissionType.PickUpWeapon:
				result = $"Pickup {amount} weapons";
				break;
			case MissionType.Headshot:
				result = $"Headshot {amount} times";
				break;
			}
			return result;
		}
	}

	public int Reward
	{
		get
		{
			int result = 0;
			switch (type)
			{
			case MissionType.Kill:
				result = Mathf.RoundToInt(50f * amount);
				break;
			case MissionType.Shoot:
				result = Mathf.RoundToInt(1.5f * amount);
				break;
			case MissionType.ClearWave:
				result = Mathf.RoundToInt(125f * amount);
				break;
			case MissionType.DealDamage:
				result = Mathf.RoundToInt(0.12f * amount);
				break;
			case MissionType.Run:
				result = Mathf.RoundToInt(0.5f * amount);
				break;
			case MissionType.PickUpWeapon:
				result = Mathf.RoundToInt(30f * amount);
				break;
			case MissionType.Headshot:
				result = Mathf.RoundToInt(25f * amount);
				break;
			}
			return result;
		}
	}

	public bool IsDone => CurrentProgress >= amount;

	public Mission(int missionOrder, MissionType type)
	{
		this.missionOrder = missionOrder;
		this.type = type;
		switch (type)
		{
		case MissionType.Kill:
			amount = UnityEngine.Random.Range(12, 21);
			break;
		case MissionType.Shoot:
			amount = 100 * UnityEngine.Random.Range(2, 6);
			break;
		case MissionType.ClearWave:
			amount = UnityEngine.Random.Range(4, 9);
			break;
		case MissionType.DealDamage:
			amount = 1000 * UnityEngine.Random.Range(2, 9);
			break;
		case MissionType.Run:
			amount = 100 * UnityEngine.Random.Range(10, 21);
			break;
		case MissionType.PickUpWeapon:
			amount = UnityEngine.Random.Range(15, 31);
			break;
		case MissionType.Headshot:
			amount = UnityEngine.Random.Range(10, 41);
			break;
		}
		Collected = false;
	}

	public Mission(int missionOrder, MissionType type, float amount)
	{
		this.missionOrder = missionOrder;
		this.type = type;
		this.amount = amount;
	}
}
